package org.example.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.example.ResultCode.R;
import org.example.educms.entity.CrmBanner;
import org.example.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author lining
 * @since 2023-11-02
 */
@CrossOrigin
@RestController
@RequestMapping("/educms/banneradmin")//管理员操作
public class CrmAdminController {
    @Autowired
    private CrmBannerService bannerService;
    //分页
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable Long page, @PathVariable Long limit){
        Page<CrmBanner> pageBanner=new Page<>(page,limit);
        bannerService.page(pageBanner,null);
        return R.ok().data("item",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }
    //tian加
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }
//    修改
@ApiOperation(value = "获取Banner")
@GetMapping("get/{id}")//获取id;
    public  R get (@PathVariable String id){
        CrmBanner banner=bannerService.getById(id);
        return  R.ok().data("item",banner);
}
//xiugai
    @ApiOperation(value = "修改Banner")
    @PutMapping("update")
    public  R updateById(@PathVariable CrmBanner banner){
        bannerService.updateById(banner);
        return R.ok();
    }
    @ApiOperation(value="删除banner")
    @DeleteMapping("remove/{id}")
    public  R remove(@PathVariable String id){
        bannerService.removeById(id);
        return  R.ok();
    }

}

